//学校详情
function gotoDetail(detailname){
	$.ajax({
        type: "POST",
        url: "/SaveSchoolDetail",
        data: {schoolname:detailname},
        dataType: "json",
        success: function(data){
        	if(data.report==0){
        		window.location.href="school_detail.html";
        	}else{
        		alert("系统错误，请稍后再试");
        	} 
        }	
	}); 
};


function showSchoolType(option0,option1,option2,option3){
	$.ajax({
        type: "POST",
        url: "/ShowSchoolTypeTip",
        data: {schoolsql:option1,schoolvalue:option2,schooltype:option3},
        dataType: "html",
        success: function(data){
        	$("#"+option0+"").html(data);
        }	
	}); 
};

function showAll(alltype,schooltip){
	$.ajax({
        type: "POST",
        url: "/ShowSchoolType",
        data: {schooltype:alltype},
        dataType: "html",
        success: function(data){
        	$("#"+schooltip+"").html(data);
        }
	}); 
};

function toRegion(){
	var searchkey=$.trim($("#title_region").html());
	var num=1;
	$.ajax({
        type: "POST",
        url: "/RegionSchoolServlet",
        data: {searchs:searchkey,page:num},
        dataType: "json",
        success: function(data){
        	if (data.report==0) {
        		window.location.href="school_list.html";
			}else{
				alert("未找到相应的数据！");
			}
        }
	}); 	
};

function groupsearch(searchkey){
	$.ajax({
        type: "POST",
        url: "/FullSearch",
        data: {searchs:searchkey},
        dataType: "json",
        success: function(data){
        	if (data.report==0) {
        		window.location.href="school_list.html";
			}else{
				alert("未找到相应的数据！");
			}
        }
	});
}

function gosearch(){
	var searchkey=$.trim($("#searchvalue").val());
	$.ajax({
        type: "POST",
        url: "/FullSearch",
        data: {searchs:searchkey},
        dataType: "json",
        success: function(data){
        	if (data.report==0) {
        		window.location.href="school_list.html";
			}else{
				alert("未找到相应的数据！");
			}
        }
	}); 	
};

//全局搜索
function gosearch1(){
	var searchkey=$.trim($("#searchvalue1").val());
	$.ajax({
        type: "POST",
        url: "/FullSearch",
        data: {searchs:searchkey},
        dataType: "json",
        success: function(data){
        	if (data.report==0) {
        		window.location.href="school_list.html";
			}else{
				alert("未找到相应的数据！");
			}
        }
	}); 	
};

//list页面汇总查询条件
function searchlist(){
	var s_area=$("#s_area").html();
	var s_level=$("#s_level").html();
	var s_time=$("#s_time").html();
	var s_nature=$("#s_nature").html();
	var s_cost=$("#s_cost").html();
	var s_action=$("#s_action").html();
	var s_others1=$("#s_others1").html();
	var s_others2=$("#s_others2").html();
	var s_others3=$("#s_others3").html();
	$.ajax({
        type: "POST",
        url: "/CommonSearch",
        data: {area:s_area,level:s_level,time:s_time,nature:s_nature,cost:s_cost,action:s_action,others1:s_others1,others2:s_others2,others3:s_others3},
        dataType: "json",
        success: function(data){
        	$("#listschoolpage").html(data.result);
        	showPage(data.total,1);
        }
	}); 	
}

//学校级别list页
function showlevel(level){
	$.ajax({
        type: "POST",
        url: "/ShowSchoolTypeAll",
        data: {schooltype:level},
        dataType: "json",
        success: function(data){
        	if (data.report==0) {
        		window.location.href="school_list.html";
			}else{
				alert("未找到相应的数据！");
			}
        }	
	});
}

//list页面条件显示
function showAdd(addkey){
	//区域
	if(addkey=="浦东新区" || addkey=="嘉定区" || addkey=="宝山区" || addkey=="闵行区" || addkey=="青浦区" || addkey=="松江区" || addkey=="金山区" || addkey=="杨浦区" || addkey=="普陀区" || addkey=="虹口区" || addkey=="静安区" || addkey=="黄浦区" || addkey=="徐汇区" || addkey=="长宁区" || addkey=="崇明县"){
		var a1 = addkey;
		$(".fi1").html("");
		$(".fi1").append("<li>区域：<p id='s_area'>" + a1 + "</p><img src='../images/close.gif' class='rmvs' /></li>");
		$(".s1 li").removeClass("dsb");
		$(".s1 li").each(function(){
			if($(this).text()==a1){
				$(this).addClass("dsb");
				return false;
			}
		});
	}
	if(addkey=="浦东" || addkey=="嘉定" || addkey=="宝山" || addkey=="闵行" || addkey=="青浦" || addkey=="松江" || addkey=="金山" || addkey=="杨浦" || addkey=="普陀" || addkey=="虹口" || addkey=="静安" || addkey=="黄浦" || addkey=="徐汇" || addkey=="长宁" || addkey=="崇明"){
		if(addkey=="崇明" || addkey=="浦东"){
			if(addkey=="崇明"){
				var a1 = addkey+"县";
			}else{
				var a1 = addkey+"新区";
			}
		}else{
			var a1 = addkey+"区";
		}
		$(".fi1").html("");
		$(".fi1").append("<li>区域：<p id='s_area'>" + a1 + "</p><img src='../images/close.gif' class='rmvs' /></li>");
		$(".s1 li").removeClass("dsb");
		$(".s1 li").each(function(){
			if($(this).text()==a1){
				$(this).addClass("dsb");
				return false;
			}
		});
	}
	if(addkey=="幼儿园" || addkey=="小学" || addkey=="初中" || addkey=="高中"){
		var a2 = addkey;
		$(".fi2").html("");
		$(".fi2").append("<li>教育程度：<p id='s_level'>" + a2 + "</p><img src='../images/close.gif' class='rmvs' /></li>");
		$(".s2 li").removeClass("dsb");
		$(".s2 li").each(function(){
			if($(this).text()==a2){
				$(this).addClass("dsb");
				return false;
			}
		});
	}
	if(addkey=="示范园幼儿园"){
		var a2 = "幼儿园";
		$(".fi2").html("");
		$(".fi2").append("<li>教育程度：<p id='s_level'>" + a2 + "</p><img src='../images/close.gif' class='rmvs' /></li>");
		$(".s2 li").removeClass("dsb");
		$(".s2 li").each(function(){
			if($(this).text()==a2){
				$(this).addClass("dsb");
				return false;
			}
		});
	}
	if(addkey=="民办小学"){
		var a2 = "小学";
		$(".fi2").html("");
		$(".fi2").append("<li>教育程度：<p id='s_level'>" + a2 + "</p><img src='../images/close.gif' class='rmvs' /></li>");
		$(".s2 li").removeClass("dsb");
		$(".s2 li").each(function(){
			if($(this).text()==a2){
				$(this).addClass("dsb");
				return false;
			}
		});
		var a4 = "民办学校";
		$(".fi4").html("");
		$(".fi4").append("<li>学校性质：<p id='s_nature'>" + a4 + "</p><img src='../images/close.gif' class='rmvs' /></li>");
		$(".s4 li").removeClass("dsb");
		$(".s4 li").each(function(){
			if($(this).text()==a4){
				$(this).addClass("dsb");
				return false;
			}
		});
	}
	if(addkey=="民办初中"){
		var a2 = "初中";
		$(".fi2").html("");
		$(".fi2").append("<li>教育程度：<p id='s_level'>" + a2 + "</p><img src='../images/close.gif' class='rmvs' /></li>");
		$(".s2 li").removeClass("dsb");
		$(".s2 li").each(function(){
			if($(this).text()==a2){
				$(this).addClass("dsb");
				return false;
			}
		});
		var a4 = "民办学校";
		$(".fi4").html("");
		$(".fi4").append("<li>学校性质：<p id='s_nature'>" + a4 + "</p><img src='../images/close.gif' class='rmvs' /></li>");
		$(".s4 li").removeClass("dsb");
		$(".s4 li").each(function(){
			if($(this).text()==a4){
				$(this).addClass("dsb");
				return false;
			}
		});
	}
	if(addkey=="重点高中"){
		var a2 = "高中";
		$(".fi2").html("");
		$(".fi2").append("<li>教育程度：<p id='s_level'>" + a2 + "</p><img src='../images/close.gif' class='rmvs' /></li>");
		$(".s2 li").removeClass("dsb");
		$(".s2 li").each(function(){
			if($(this).text()==a2){
				$(this).addClass("dsb");
				return false;
			}
		});
		var a9 = "重点学校";
		$(".fi9").append("<li>其他信息：<p id='s_others3'>" + a9 + "</p><img src='../images/close.gif' class='rmvs' /></li>");
		$(".other3").addClass("dsb");
	}
	if(addkey=="9年制学校" || addkey=="12年制学校"){
		var a3 = addkey;
		$(".fi3").html("");
		$(".fi3").append("<li>学制：<p id='s_time'>" + a3 + "</p><img src='../images/close.gif' class='rmvs' /></li>");
		$(".s3 li").removeClass("dsb");
		$(".s3 li").each(function(){
			if($(this).text()==a3){
				$(this).addClass("dsb");
				return false;
			}
		});
	}
}

//list页面分页
function showPage(total,index){
	//初始化分页页脚
	document.getElementById("pagnation").innerHTML='';
	var pageTmp = "";
	pageTmp = pageTmp + '共'+total+'条记录&nbsp;&nbsp;&nbsp;'+ index + '/' + (Math.ceil(total/3)) +'页&nbsp;&nbsp;&nbsp;';
    var next = parseInt(index)+1;
    if(next > ((Math.ceil(total/3)))){
    	next = ((Math.ceil(total/3)));
    }
    pageTmp = pageTmp + '&nbsp;&nbsp;&nbsp;<a href="javascript:showMes(1);">第一页</a>&nbsp;&nbsp;&nbsp;<a href="javascript:showMes('+(index-1)+');">上一页</a>&nbsp;&nbsp;&nbsp;<a href="javascript:showMes('+next+');">下一页</a>&nbsp;&nbsp;&nbsp;<a href="javascript:showMes('+(Math.ceil(total/3))+');">最后页</a>';
    if (total==0) {
    	$("#listschoolpage").append( "<div><p style='text-align:center'>未查到任何相关学校！</p></div>");
	}else{
		pageTmp = pageTmp + '&nbsp;&nbsp;&nbsp;<select id="jump" name="jump" onchange="javascript:jumpPage();"> ';
	     for(var i=0;i<(total/3);i++){
	    	 if(i==(index-1)){
	    	     	pageTmp = pageTmp + '<option value="'+(i+1)+'" selected>'+(i+1)+'</option>';
	     	}else{
	         	pageTmp = pageTmp + '<option value="'+(i+1)+'">'+(i+1)+'</option>';
	     	}
	     }
	     pageTmp = pageTmp +'</select>';
	}
     
	$("#pagnation").append(pageTmp);
	//显示第一页
    $('.page:eq(0)').css('display','block');
}
	
function jumpPage(){
	showMes(document.getElementById("jump").options[document.getElementById("jump").selectedIndex].value);
}

function showMes(index){
	$.ajax({
        type: "POST",
        url: "/ChangePage",
        data: {page:index},
        dataType: "json",
        success: function(data){
        	$("#listschoolpage").html(data.result);
        	showPage(data.total,index);
        }	
	});
}